using System.Text;
using System.IO;
using BizTalk.BuildGenerator.MetaData;

namespace BizTalk.BuildGenerator.BuildFrameworks.Default.FileBuilders
{
    /// <summary>
    /// Builds the App.Setup.targets file
    /// </summary>
    public class ApplicationPropertiesFileBuilder : IFileBuilder
    {
        private const string FileExtension = ".properties";

        #region IFileBuilder Members
        /// <summary>
        /// implements file builder
        /// </summary>
        /// <param name="args"></param>
        public void Build(GenerationArgs args)
        {
            var fileBuilder = new StringBuilder();
            fileBuilder.Append(Properties.Resources.App_properties);
            GenerationTags.ReplaceTags(fileBuilder, args);

            var filePath = args.OutputFolder + @"\" + args.ApplicationDescription.Name + FileExtension;
            FileHelper.ConfigureForSourceCodeRoot(fileBuilder, args);

            //The root tag is only replaced here so it is not overwritten when configuring the root path everywhere else
            fileBuilder.Replace(GenerationTags.SourceCodeRootTag, Path.GetDirectoryName(args.SolutionPath) + @"\");
            fileBuilder.Replace("@SolutionName@", Path.GetFileName(args.SolutionPath));
            FileHelper.WriteFile(filePath, fileBuilder);
        }

        #endregion
    }
}